package com.wxq.demo.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.FanoutExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class SenderConf {
    @Bean(name = "Amessage")
    public Queue Amessage() {
        return new Queue("fanout.A");
    }

    @Bean(name = "Bmessage")
    public Queue Bmessage() {
        return new Queue("fanout.B");
    }

    @Bean(name = "Cmessage")
    public Queue Cmessage() {
        return new Queue("fanout.C");
    }

    @Bean
    FanoutExchange fanoutExchange() {
        //配置广播
        return new FanoutExchange("fanoutExchange");
    }

    @Bean
    Binding bindingExchangeA(@Qualifier("Amessage") Queue Amessage, FanoutExchange fanoutExchange) {
        return BindingBuilder.bind(Amessage).to(fanoutExchange);
    }

    @Bean
    Binding bindingExchangeB(@Qualifier("Bmessage") Queue Bmessage, FanoutExchange fanoutExchange) {
        return BindingBuilder.bind(Bmessage).to(fanoutExchange);
    }

    @Bean
    Binding bindingExchangeC(@Qualifier("Cmessage") Queue Cmessage, FanoutExchange fanoutExchange) {
        return BindingBuilder.bind(Cmessage).to(fanoutExchange);
    }
}
